import 'dart:convert';

import 'package:flutter/material.dart';

class JsonMapView extends StatelessWidget {
  const JsonMapView({super.key});

  @override
  Widget build(BuildContext context) {
    //Map转换成Json
    Map userInfo = {"username": "汪方晨", "age": 33};
    print(json.encode(userInfo));

    String jsonStr = '{"username":"汪方晨","age":33}';
    Map userInfoData = json.decode(jsonStr);
    userInfoData.forEach((k, v) {
      print(' 遍历得到每一条数据:$k  $v');
    });
    return Scaffold(
      appBar: AppBar(title: Text('Json Map转换')),
      body: Center(
        child: Text('hello'),
      ),
    );
  }
}
